package com.youfang.sixthmedia.common;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.gzit.adapter.CustomerListAdapter;
import com.gzit.utils.AndroidUtils;
import com.gzit.utils.StringUtils;
import com.youfang.sixthmedia.R;
import com.youfang.sixthmedia.message.model.Building;
import com.youfang.sixthmedia.message.model.DetailBuilding;

public class BuildingAdapter extends CustomerListAdapter<Building> {

	public BuildingAdapter(Context context) {
		super(context, R.layout.building_item);
	}

	public long getItemId(int position) {
		return this.getmObjects().get(position).innerID;
	}

	@Override
	protected void render(Building item, View view) {

		// building logo
		ImageView photo = (ImageView) view.findViewById(R.id.photo);

		if (YoufangContext.showPic && item.logoBitmap != null) {
			photo.setImageBitmap(item.logoBitmap);
		} else {
			photo.setImageResource(R.drawable.nophoto);
		}

		// groupon or discount...
		ImageView buildingIndicator = (ImageView) view
				.findViewById(R.id.building_indicator);
		if (item.grouponbydev == Building.GROUP_ON) {
			buildingIndicator.setImageResource(R.drawable.tuangou_fg);
		} else {
			buildingIndicator.setImageDrawable(null);

		}

		// other info
		TextView name = (TextView) view.findViewById(R.id.buildingname);
		AndroidUtils.boldText(name);
		name.setText(item.buildingname);
		AndroidUtils.boldText(name);

		TextView readnum = (TextView) view.findViewById(R.id.readnum);

		readnum.setText(StringUtils.isStickBlank(item.readnum) ? ""
				: item.readnum + "次浏览");

		TextView type = (TextView) view.findViewById(R.id.buildingtype);
		type.setText(item.buildingtype);

		TextView price = (TextView) view.findViewById(R.id.price);
		price.setText("0".equals(item.price) ? "价格待定" : item.price + "元/㎡");

		TextView address = (TextView) view.findViewById(R.id.address);
		address.setText(item.address);

		// Is it a detail building...
		if (item instanceof DetailBuilding) {
			TextView distance = (TextView) view.findViewById(R.id.distance);
			distance.setText(String.format("%.0f米",
					((DetailBuilding) item).distance));

		}

	}
}